package com.itheima.edu.info.manager.day17;

import org.dom4j.Attribute;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

public class DOMShiYan {
    public static void main(String[] args) throws DocumentException {
        //创建解码器对象
        SAXReader saxreader=new SAXReader();
        Document document =saxreader.read(new File("D:\\jinjie\\jinjie\\src\\com\\itheima\\edu\\info\\manager\\day17\\a.xml"));
        Element rootElement = document.getRootElement();
        List<Element> student = rootElement.elements("student");
        List<Student> list=new ArrayList();
        for (Element element : student) {
            Attribute id = element.attribute("id");
            Element elementname = element.element("name");
            Element elementage = element.element("age");
            String idValue = id.getValue();
            String name = elementname.getText();
            int  age = Integer.parseInt(elementage.getText());
            Student studnet =new Student(idValue ,name,age);
            list.add(studnet);
        }
        for (Student student1 : list) {
            System.out.println(student1);
        }
    }
}
